﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;

namespace Jxym.wlkc2011
{
    public partial class picslr : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["sitename"] != null && Request.Params["m"] != null)
                {
                    sitename = Request.Params["sitename"];

                    m = Request.Params["m"];

                    if (Request.Params["id"] != null)
                    {
                        LoadContent(Request.Params["id"]);
                    }
                    else
                    {
                        if (Request.Params["c"] != null)
                        {
                            LoadDesc(Request.Params["c"]);
                        }
                        else
                        {
                            LoadDesc(m);
                        }
                    }
                }
            }
        }

        private void LoadContent(string p)
        {
            MsSqlDal<Cms_Content> cc = new MsSqlDal<Cms_Content>();

            Cms_Content ccInfo = cc.GetModel(p);

            if (ccInfo != null)
            {
                p_desclr.Visible = true;
                listlr.Visible = false;
                Label1.Visible = false;
                labTitle.Text = ccInfo.Title;
                labUser.Text = ccInfo.AddUser;
                labAddTime.Text = ccInfo.AddTime.ToString("yyyy-MM-dd");
                labContent.Text = Module.CMS.Public.cmsPublic.ViewContent(sitename, ccInfo, "660px", "920px");
            }
            else
            {
                p_desclr.Visible = false;
                listlr.Visible = false;
                Label1.Visible = true;
            }
        }

        MsSqlDal<Cms_Content> cc = new MsSqlDal<Cms_Content>();

        private void LoadDesc(string mid)
        {
            MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

            Cms_ContentClass cccInfo = ccc.GetModel(mid);

            if (cccInfo != null)
            {
                labMenuTitle.Text = cccInfo.Title;
            }

            IList<Cms_Content> ccList = cc.GetList("ContentClassID=" + mid, null, "", 0);

            if (ccList.Count > 1)
            {
                p_desclr.Visible = false;
                listlr.Visible = true;
                Label1.Visible = false;
                BinData();
            }
            else if (ccList.Count == 1)
            {
                p_desclr.Visible = true;
                listlr.Visible = false;
                Label1.Visible = false;
                labTitle.Text = ccList[0].Title;
                labUser.Text = ccList[0].AddUser;
                labAddTime.Text = ccList[0].AddTime.ToString("yyyy-MM-dd");
                labContent.Text = Module.CMS.Public.cmsPublic.ViewContent(sitename, ccList[0], "660px", "920px");
            }
            else
            {
                Label1.Visible = true;
                p_desclr.Visible = false;
                listlr.Visible = false;
            }
        }

        public string sitename { get; set; }
        public string m { get; set; }
        public string _id { get; set; }

        public void BinData()
        {
            AspNetPager1.RecordCount = cc.GetPageCount("ContentClassID=" + m, null);
            Repeater1.DataSource = cc.GetPageList("ContentClassID=" + m, null, AspNetPager1.StartRecordIndex, AspNetPager1.PageSize);
            Repeater1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BinData();
        }
    }
}